<!--
 * new page
 * @author: YK
 * @since: 2023-12-01
 * index.vue
-->
<template>
  <div class="list-tabs__item">
    <el-tabs>
      <el-tab-pane
        v-for="(item, index) in list"
        :key="index"
        :label="item.title"
      >
        <el-scrollbar max-height="300px">
          <div
            class="container"
            v-for="(item1, index1) in item.content"
            :key="index1"
            @click="handleClick(item1, index1)"
          >
            <div class="avatar">
              <el-avatar size="small" :src="item1.avatar"></el-avatar>
            </div>
            <div class="content">
              <div v-if="item1.title" class="title">
                <div>{{ item1.title }}</div>
                <el-tag :type="item1.tagType" v-if="item1.tag" size="small">{{
                  item1.tag
                }}</el-tag>
              </div>
              <div v-if="item1.desc" class="time">{{ item1.desc }}</div>
              <div v-if="item1.time" class="time">{{ item1.time }}</div>
            </div>
          </div>
          <div class="actions">
            <div
              class="a-item"
              @click="clickAction(action, index)"
              :class="{ border: index !== actions.length - 1 }"
              v-for="(action, index) in actions"
              :key="index"
            >
              <div class="a-icon" v-if="action.icon">
                <component :is="`el-icon${toLine(action.icon)}`"></component>
              </div>
              <div class="a-text">{{ action.text }}</div>
            </div>
          </div>
        </el-scrollbar>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script setup lang="ts">
import { toLine } from "../../../utils";
import { ListOptions, ActionsOptions } from "./types";
withDefaults(
  defineProps<{
    list: ListOptions[];
    actions: ActionsOptions[]; //操作内容
  }>(),
  {
    actions: () => [],
    list: () => [],
  }
);
let emits = defineEmits(["clickItem", "clickAction"]);
const handleClick = (item: ListOptions, index: number) => {
  emits("clickItem", item, index);
};
const clickAction = (action: ActionsOptions, index: number) => {
  emits("clickAction", action, index);
};
</script>

<style scoped lang="scss">
.container {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  cursor: pointer;
  &:hover {
    background-color: #e6f6ff;
  }
  .avatar {
    flex: 1;
  }
  .content {
    flex: 3;
    .title {
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 100%;
      font-size: 12px;
    }
    .time {
      font-size: 10px;
      color: #999;
      margin-top: 4px;
    }
  }
}
.actions {
  height: 50px;
  display: flex;
  align-items: center;
  border-top: 1px solid #ebeef5;
  .a-item {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 50px;
    margin-top: 10px;
  }
  .a-icon {
    margin-right: 4px;
    position: relative;
    top: 2px;
  }
}
.border {
  border-right: 1px solid #ebeef5;
}
</style>
